package com.yk.framework.entity;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

/**
 * @author lifetime
 * 
 */
public class EntityPKCache {
	static EntityPKCache pkCache = new EntityPKCache();
	private HashMap<String, String> typeMapEntity;
	private HashMap<String, String> typeMapTable;

	private EntityPKCache() {
		typeMapEntity = new HashMap<String, String>();
		typeMapTable = new HashMap<String, String>();
		init();
	}

	public HashMap<String, String> getTypeMapEntity() {
		return typeMapEntity;
	}

	public HashMap<String, String> getTypeMapTable() {
		return typeMapTable;
	}

	protected void init() {
		Properties properties = new Properties();
		InputStream inputStream = null;
		try {
			inputStream = this.getClass().getResourceAsStream("/entity_pk.properties");
			properties.load(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				inputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		Set<Object> keys = properties.keySet();
		for (Iterator<Object> it = keys.iterator(); it.hasNext();) {
			String key = (String) it.next();
			String value = (String) properties.get(key);
			String[] ss = value.split(",");
			typeMapEntity.put(key, ss[0]);
			typeMapTable.put(key, ss[1]);
		}
	}

	public static EntityPKCache getCache() {
		return pkCache;
	}
	
	public static void main(String[] args) {
		System.out.println(EntityPKCache.getCache().getTypeMapEntity());
		System.out.println(EntityPKCache.getCache().getTypeMapTable());
	}
}
